package com.thinkfit.jy.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.common.lib.constant.Constants;
import com.common.lib.fragment.BaseFragment;
import com.common.lib.mvp.contract.EmptyContract;
import com.common.lib.mvp.presenter.EmptyPresenter;
import com.thinkfit.jy.R;
/**
 * 个人中心
 */
public class UserProfileFragment extends BaseFragment<EmptyContract.Presenter> implements EmptyContract.View {
    @NonNull
    @Override
    protected EmptyContract.Presenter onCreatePresenter() {
        return new EmptyPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_user_profile;
    }

    @Override
    protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) {
        int index = getArguments().getInt(Constants.BUNDLE_EXTRA, 0);
        FragmentTransaction ft = getChildFragmentManager().beginTransaction();
        if (index == 0) {
            ft.add(R.id.fl, new PersonalDataFragment().setParentFragment(this));//用户数据
        } else if (index == 1) {
            ft.add(R.id.fl, new SportRecordFragment().setParentFragment(this));//用户累计数据
        } else {
            ft.add(R.id.fl, new TrainingCourseFragment().setParentFragment(this));//用户训练课程记录
        }
        ft.commit();
    }

    @Override
    public void onClick(View v) {

    }

    public void toFragment(Fragment fragment) {
        FragmentTransaction ft = getChildFragmentManager().beginTransaction();
        ft.replace(R.id.fl, fragment);
        ft.addToBackStack(null);
        ft.commit();
    }

    public static UserProfileFragment getInstance(int index) {
        Bundle bundle = new Bundle();
        bundle.putInt(Constants.BUNDLE_EXTRA, index);
        UserProfileFragment fragment = new UserProfileFragment();
        fragment.setArguments(bundle);
        return fragment;
    }
}
